package www.dianbaozu.com.ui.chat.findFriend.holder

import android.annotation.SuppressLint
import android.view.View
import androidx.databinding.DataBindingUtil
import com.netease.nim.uikit.api.SessionHelper
import com.netease.nim.uikit.business.uinfo.UserInfoHelper
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseQuickAdapter
import com.netease.nim.uikit.common.ui.recyclerview.holder.BaseViewHolder
import com.netease.nim.uikit.common.ui.recyclerview.holder.RecyclerViewHolder
import com.netease.nim.uikit.databinding.ItemFriendsBinding
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum
import com.netease.nimlib.sdk.search.model.MsgIndexRecord

class FindFriendRecentContactViewHolder(baseQuickAdapter: BaseQuickAdapter<Any, BaseViewHolder>) :
    RecyclerViewHolder<BaseQuickAdapter<Any, BaseViewHolder>, BaseViewHolder, Any>(
        baseQuickAdapter
    ) {
    private var binding: ItemFriendsBinding? = null

    @SuppressLint("SetTextI18n")
    override fun convert(
        holder: BaseViewHolder,
        data: Any,
        position: Int,
        isScrolling: Boolean
    ) {
        if (data is MsgIndexRecord) {
            data.let { msgIndexRecord ->
                binding = DataBindingUtil.bind(holder.itemView)
                binding?.apply {
                    tvSubtitle.visibility = View.VISIBLE
                    imgArrow.visibility = View.GONE
                    slUnreadMessage.visibility = View.GONE
                    imgOnlineStatus.visibility = View.GONE

                    tvTopStatus.visibility = View.GONE
                    tvTopStatus.text = "私聊记录"

                    ivAvatar.loadBuddyAvatar(msgIndexRecord.sessionId)
                    tvTitle.text =
                        UserInfoHelper.getUserTitleName(
                            msgIndexRecord.sessionId,
                            SessionTypeEnum.P2P
                        )
                    tvSubtitle.text = "${msgIndexRecord.count}条相关记录"
                    setItemClick {
                        SessionHelper.startP2PSession(
                            root.context,
                            msgIndexRecord.sessionId,
                            msgIndexRecord.message
                        )
                    }
                }
            }
        }
    }
}